var goHelper = (function () {
	var deadPieces = [];
	function hasDeadPieces(pos, status, allStatus) {
		deadPieces = [];
		var pieces = [];
		if (pos > 0 && pos%19 != 0 && !hasWay(pos - 1, status, allStatus, pieces)) {
			deadPieces = deadPieces.concat(pieces);
		}
		pieces = [];
		if (pos >= 19 && !hasWay(pos - 19, status, allStatus, pieces)) {
			deadPieces = deadPieces.concat(pieces);
		}
		pieces = [];
		if (pos <= 359 && pos%19 != 18 && !hasWay(pos + 1, status, allStatus, pieces)) {
			deadPieces = deadPieces.concat(pieces);
		}
		pieces = [];
		if (pos <= 341 && !hasWay(pos + 19, status, allStatus, pieces)) {
			deadPieces = deadPieces.concat(pieces);
		}
		return deadPieces.length > 0;
	}
	function hasWay(pos, status, allStatus, pieces) {
		if (allStatus[pos] == '0') return true;
		if (allStatus[pos] != status) return false;
		pieces.push(pos);
		allStatus[pos] = status == '1' ? '2' : '1';
		if (pos > 0 && pos%19 != 0 && hasWay(pos - 1, status, allStatus, pieces)) {
			allStatus[pos] = '0';
			return true;
		}
		if (pos >= 19 && hasWay(pos - 19, status, allStatus, pieces)) {
			allStatus[pos] = '0';
			return true;
		}
		if (pos <= 359 && pos%19 != 18 && hasWay(pos + 1, status, allStatus, pieces)) {
			allStatus[pos] = '0';
			return true;
		}
		if (pos <= 341 && hasWay(pos + 19, status, allStatus, pieces)) {
			allStatus[pos] = '0';
			return true;
		}
		return false;
	}
	function getDeadPieces() {
		return deadPieces;
	}
	return { 
		'hasDeadPieces': hasDeadPieces,
		'getDeadPieces': getDeadPieces,
		'hasWay': hasWay
	};
})();
